home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.2 KB  |  51 lines

  1.  
  2. /* julian date */
  3.  
  4. #include <osbind.h>
  5.  
  6. /* days in months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
  7.  
  8. short month_days[] = {    0,
  9.             31, 
  10.             31 + 28,
  11.             31 + 28 + 31,
  12.             31 + 28 + 31 + 30,
  13.             31 + 28 + 31 + 30 + 31,
  14.             31 + 28 + 31 + 30 + 31 + 30,
  15.             31 + 28 + 31 + 30 + 31 + 30 + 31,
  16.             31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
  17.             31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
  18.             31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
  19.             31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
  20.             };
  21. /* note that the value returned from this is NOT suitable for calling 
  22.    ctime on */
  23.  
  24. long time(place)
  25. long * place;
  26. {
  27.   int today = Tgetdate();
  28.   int now = Tgettime();
  29.   int year, month, day, hour, min, sec;
  30.   long result;
  31.  
  32.   year = ((today >> 9) & 0x7F);
  33.   month = (today >> 5) & 0x0F;
  34.   if ((month < 1) || (month > 12))
  35.     month = 1;
  36.   day = today & 0x1F;
  37.   hour = (now >> 11) & 0x1F;
  38.   min = (now >> 5) & 0x3F;
  39.   sec = (now & 0x01F) * 2;
  40.  
  41.   result =     sec + 
  42.         (min * 60) + 
  43.         (hour * 3600) + 
  44.         ((day + month_days[month]) * 86400) +
  45.         year * 31536000;
  46. /* ignores leap years for now */
  47.   if (place)
  48.     *place = result;
  49.   return(result);
  50. }
  51.